
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@include file="/layout/header.jspf"%>

<%@page import="java.util.List"%>
<%@page import="java.sql.*"%>
<%@page import="org.barman.dao.ItemDAO"%>
<%@page import="org.barman.pojo.Item"%>

<script type="text/javascript">
	function add() {
		$("#lastItemTableRow")
				.before(
						"<tr><td>"
								+ $("#itemsSelectCell").html()
								+ "</td><td><input type=\"text\" name=\"itemQuantities[]\" /></td></tr>");
	}
</script>

<%
	String id = request.getParameter("id");
	request.setAttribute("id", id);

	ItemDAO itemDAO = new ItemDAO();
	List<Item> itemList = itemDAO.getAll();

	pageContext.setAttribute("items", itemList);
%>
<br>
<h1>Waiter Main Page</h1>
<br>
<form action="../ManageOrderServlet?id=${id}" method="post">
	<div style="text-align: center; margin: 0 auto;">
		<table id="itemTable" style="margin: 0 auto;">
			<tr>
				<td>Item:</td>
				<td>Quantity:</td>
			</tr>
			<tr>
				<td id="itemsSelectCell"><select name="itemIds[]">
						<c:forEach items="${items}" var="item">
							<option value="${item.id}">${item.name}</option>
						</c:forEach>
				</select></td>
				<td><input type="text" name="itemQuantities[]" /></td>
			</tr>
			<tr id="lastItemTableRow">
				<td><br /> <input type="submit" value="Save Order" /></td>
				<td colspan="2"><br /> <input type="button" onclick="add();" value="Add More" /></td>
			</tr>
		</table>
		<br />

	</div>
</form>

<%@include file="/layout/footer.jspf"%>
